package cn.edu.Day09;

public class BaoShe {
    private String name;
    private String title;
    boolean deng  = true;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public synchronized void set(String name,String title){
        if(this.deng == false){
            try {
                super.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        this.setName(name);
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.setTitle(title);

        this.deng = false;
        super.notify();
    }
    public synchronized void get(){
        if(this.deng == true){
            try {
                super.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(this.getName()+"--"+this.getTitle());
        this.deng = true;
        super.notify();
    }
}
